<%-- 
    Document   : yqxm
    Created on : 2016-7-20, 19:46:14
    Author     : cxhd
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@include file="../../link.jsp" %>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>仪器与项目匹配--通道号</title>
    </head>
    <body ng-app="yqxm" ng-controller="ppManager">
<!--        <style>
            body{background-color: #FFF}
            tr>th{ padding: 1px}
            dd
            th{
                border: solid 1px gray;
                width:30px;
                overflow: hidden;text-overflow: ellipsis;white-space: nowrap;
                course:hand;
            }
        </style>-->
        <div >
            <!--<div class="col w-lg bg-light dk b-r bg-auto" id="aside" style="background-color: #ffffff;width: 100%">-->
            <!--仪器显示-->
            <div style="float: left;width:18%;">
                <div class="wrapper bg b-b" style="height: 50px;">
                    <!--<button class="btn btn-sm btn-success pull-right" ui-toggle-class="timeline-center" target=".timeline">Center</button>-->
                    <h4 class="m-n font-thin">仪器浏览与选择</h4>
                </div>
                <div class="wrapper" >
                    <form class="ng-pristine ng-valid">
                        <table  class="table table-striped table-bordered  table-hover"   >
                            <tr >
                                <th class="table-id">仪器型号</th>
                                <th class="table-title">仪器名</th>
                                <!--<th class="table-type">仪器类型</th>-->
                            </tr>
                            <tr  ng-repeat="pdt in pdts" ng-click="checkDevice(pdt)">
                                <td>{{pdt.DEVICEMODEL}}</td>
                                <td>{{pdt.DEVICENAME}}</td>
                                <!--<td>{{pdt.DEVICETYPE1}}</td>-->
                            </tr>
                        </table>
                    </form>
                </div>
            </div>
            <div style="float: left;width:25%;height: 100%;overflow: auto">
                <div class="wrapper bg b-b" style="height: 49px;padding: 1px;"  >
                    <!--<button class="btn btn-sm btn-success pull-right" ui-toggle-class="timeline-center" target=".timeline">Center</button>-->
                    <div style="margin-left:15%">  样本类型：
                        <select ng-model="PK1" ng-options="sam.PK as sam.SAMPLEDESCRIBE for sam in sams"   style="width: 90px" >
                            <option  value="">不选样本</option>
                        </select> 

                    </div>
                    <div style="margin-left:15%">
                        项目代码：<input type="text" ng-model="TESTID" style="width:90px" /> 
                        <!--<button ng-click="getLisTestByT()"  >收索</button>-->
                        &nbsp;&nbsp; <button ng-click="getLisTestByT()"  class="btn btn-success btn-sm"><span class="fa fa-search"></span>&nbsp;&nbsp;搜索</button>
                    </div>
                    <!--<button ng-click="getLisTest()">收索</button>-->
                </div>
                <div class="wrapper" >
                    <form class="ng-pristine ng-valid">
                        <table  class="table table-striped table-bordered  table-hover"   >
                            <tr>
                                <th class="table-id"><input type="checkbox"></th>
                                <th class="table-title">项目代码</th>
                                <th class="table-title">项目名</th>

                            </tr>
                            <tr  ng-repeat="test in tests" ng-click="checkTest($index)">
                                <td><input type="checkbox" ng-model="test.check"></td>
                                <td>{{test.TESTID}}</td>
                                <td>{{test.CHINESENAME}}</td>   
                            </tr>
                        </table>
                    </form>
                    <footer class="panel-heading">
                        <div class="row">
                            <div style="text-align: center" >                
                                <pagination ng-change="pageChanged()" previous-text="上一页" next-text="下一页" first-text="第一页" last-text="最后一页" ng-model="data.currentPage" items-per-page="data.pageSize" total-items="data.bigTotalItems" ng-model="data.bigCurrentPage" max-size="data.maxSize" class="pagination-sm" boundary-links="true" rotate="false" num-pages="numPages"></pagination>

                            </div>
                        </div>
                    </footer>
                </div>

            </div>
            <div style="float: left;width:57%;overflow: auto">
                <div class="wrapper bg b-b" style="height: 50px;">
                    当前仪器:<input type="text" ng-model="DEVICENAME"/>
                    <button class="btn m-b-xs btn-sm btn-primary btn-addon" ng-click="addPpDeviceTest()"><i class="fa fa-plus"></i>添加项目</button>
                    <!--<button class="btn m-b-xs btn-sm btn-primary btn-addon" ng-click="updatTestPK()"><i class="fa fa-save"></i>updatTestPK</button>-->
                </div>
                <div class="wrapper" style="width: 800px" >
                    <form class="ng-pristine ng-valid">
                        <table  class="table table-striped table-bordered  table-hover"   >
                            <tr>
                                <!--<th class="table-id">仪器名</th>-->
                                <th class="table-title" style="width:60px;word-break:keep-all;
                                    white-space:nowrap;
                                    overflow:hidden;
                                    text-overflow:ellipsis;">项目名</th>
                                <th class="table-title">项目代码 </th>
<!--                                <th class="table-title">通道号</th>-->
                                <th class="table-title">打印序号</th>
                                <th class="table-title">单位 </th>
                                <th class="table-title">最低</th>
                                <th class="table-title">最高</th>
<!--                                <th class="table-title">女最低</th>
                                <th class="table-title">女最高</th>-->
                                <th class="table-title">默认值</th>
                                <th class="table-title">留小数位</th>
                                <th class="table-title">操作</th>
                            </tr>
                            <tr  ng-repeat="ppdt in ppdts" >
                                <!--<td>{{ppdt.DEVICENAME}}</td>-->
                                <td ><div style="width:70px; white-space:nowrap;overflow:hidden;text-overflow:ellipsis;">{{ppdt.CHINESENAME}}</div></td>
                                <td><div style="width:60px; white-space:nowrap;overflow:hidden;text-overflow:ellipsis;">{{ppdt.TESTID}}</div></td>
                              
                                <td><input type="text" ng-model="ppdt.DATA1" style="width:40px"></td>

                                <td><select ng-model="ppdt.UNIT" ng-options=" unit.UNITNAME as unit.UNITNAME for unit  in units" >

                                    </select>   </td>
                                <td><input type="text" ng-model="ppdt.MREFLO0" style="width:40px"></td>
                                <td><input type="text" ng-model="ppdt.MREFHI0" style="width:40px"></td>
                                <td><input type="text" ng-model="ppdt.DATA2" style="width:40px"></td>
<!--                                <td><input type="text" ng-model="ppdt.FREFLO0" style="width:40px"></td>
                                <td><input type="text" ng-model="ppdt.FREFHI0" style="width:40px"></td>-->
                                <td><input type="text" ng-model="ppdt.Decimalplace" style="width:40px"></td>


                                <td><button ng-click="deletePp(ppdt)" class="btn btn-danger btn-xs"><span class="fa fa-bolt"></span>&nbsp;删除</button> 
                                    <button class="btn btn-success btn-xs" ng-click="updatePp(ppdt)"><span class="fa fa-save"></span>保存</button>

                                    <!--<button class="btn m-b-xs btn-sm btn-success btn-addon" ng-click="updatePri(ppdt)">修改打印次序</button>-->
                                </td>
                            </tr>
                        </table>
                    </form>
                    <footer class="panel-heading">
                        <div class="row">
                            <div style="text-align: center" >                
                                <pagination ng-change="pageChanged2()" previous-text="上一页" next-text="下一页" first-text="第一页" last-text="最后一页" ng-model="data2.currentPage" items-per-page="data2.pageSize" total-items="data2.bigTotalItems" ng-model="data2.bigCurrentPage" max-size="data2.maxSize" class="pagination-sm" boundary-links="true" rotate="false" num-pages="numPages"></pagination>

                            </div>
                        </div>
                    </footer>
                </div>
            </div>
            <!--<div style="width:200px; white-space:nowrap;overflow:hidden;text-overflow:ellipsis; border:1px solid red"></div>-->
            <!--</div>-->

        </div>
    </body>

    <script>
        angular.module("yqxm", ['baseModule', 'ui.bootstrap'])
                .controller("ppManager", function ($scope, $http, base) {
                    $scope.DEVICENAME = "";
                    $scope.getLisDevices = function () {//仪器显示
                        base.post("pp/getLisDevices").get(function (data) {
                            console.log(data);
                            if (data) {
                                $scope.pdts = data;
//                         $scope.DEVICEID=data[0].DEVICEID;
//                         $scope.DEVICENAME=data[0].DEVICENAME;
//                         $scope.$apply();
                            }
                        })
                    }
                    $scope.getLisDevices();
                    $scope.getSamp = function () {//样本类型显示
                        base.post("pp/getLisSam").get(function (data) {
                            if (data) {
                                $scope.sams = data;
//                         $scope.$apply();
                            }
                        })
                    }
                    $scope.getSamp();

                    $scope.data = {currentPage: 1};
                    $scope.setPage = function (pageNo) {
                        $scope.data.currentPage = pageNo;
                    };
                    $scope.pageChanged = function () {
                        $scope.getLisTestByT();
                    };
                    $scope.data.maxSize = 1;
                    $scope.data.bigTotalItems = 20;
                    $scope.data.bigCurrentPage = 1;
                    $scope.data.pageSize = 10;

//             $scope.getLisTest=function(){//通过样本类型筛选项目
//                 base.post("pp/getLisTest",{PK:$scope.PK1,pageSize: $scope.data.pageSize, currentPage: $scope.data.currentPage}).get(function(data){
//                     if(data){
//                         $scope.tests=data.list;
//                           $scope.data.bigTotalItems = data.totalRow; 
////                         $scope.$apply();
//                     }
//                 })
//             }


                    $scope.TESTID = "";
                    $scope.getLisTestByT = function () {//通过项目代码筛选项目
                        base.post("citemtest/getLisTestByPy", {PK: $scope.PK1, TESTID: $scope.TESTID, pageSize: $scope.data.pageSize, currentPage: $scope.data.currentPage}).get(function (data) {
//                     console.log(data);
                            if (data) {
                                $scope.tests = data.list;
                                $scope.data.bigTotalItems = data.totalRow;
//                         $scope.$apply();
                            }
                        })
                    }
                    $scope.getLisTestByT();
                    $scope.checkDevice = function (tmp) {
                        $scope.DEVICEID = tmp.DEVICEID;
                        $scope.DEVICENAME = tmp.DEVICENAME;
                        $scope.DEVICEPK = tmp.DEVICEPK;
                        $scope.getPpDeviceT();
                    }
                    $scope.checkTest = function (index) {//点击行选择复选框
                        if ($scope.tests[index].check) {
                            $scope.tests[index].check = false;
                        } else {
                            $scope.tests[index].check = true;
                        }
                    }
                    $scope.checkT = [];
                    $scope.addPpDeviceTest = function () {
                        if ($scope.DEVICENAME == "") {
                            alert("请选择匹配仪器");
                            return;
                        }
                        for (var i = 0; i < $scope.tests.length; i++) {//获取选中的项目
                            if ($scope.tests[i].check) {
                                $scope.checkT.push($scope.tests[i]);
                            }
                        }
                        if ($scope.checkT.length == 0) {
                            alert("请先为仪器选择项目在匹配");
                            return;
                        }
                        var checktes = JSON.stringify($scope.checkT);
                        base.post("pp/savePpDeviceTest", {TESTS: checktes, DEVICEID: $scope.DEVICEID, DEVICEPK: $scope.DEVICEPK}).get(function (data) {

                            if (data == 'true') {

                                $scope.getPpDeviceT();
                                $scope.checkT = [];
                            }
                        })
                    }
                    $scope.data2 = {currentPage: 1};

                    $scope.pageChanged2 = function () {
                        $scope.getPpDeviceT();
                    };
                    $scope.data2.maxSize = 1;
                    $scope.data2.bigTotalItems = 20;
                    $scope.data2.bigCurrentPage = 1;
                    $scope.data2.pageSize = 10;
                    $scope.getPpDeviceT = function () {
                        base.post("pp/getPpDeviceTest", {DEVICEID: $scope.DEVICEID, pageSize: $scope.data2.pageSize, currentPage: $scope.data2.currentPage}).get(function (data) {
                            console.log(data);
                            if (data) {
                                $scope.ppdts = data.list;
                                $scope.data2.bigTotalItems = data.totalRow;
//                        $scope.$apply();
                            }
                        })
                    }
                    $scope.getPpDeviceT();

                    $scope.deletePp = function (tmp) {
                        base.post("pp/deletePpDeviceTest", {DEVICEID: tmp.DEVICEID, TESTID: tmp.TESTID}).get(function (data) {
                            if (data == 'true') {
                                $scope.getPpDeviceT();
                            }
                        })
                    }

                    $scope.updatePp = function (ppdt) {
                        base.post("pp/updatePpDeviceTest", {PK: ppdt.PK, DEVICEID: ppdt.DEVICEID, TESTID: ppdt.TESTID, DATA2: ppdt.DATA2, DATA1: ppdt.DATA1,
                            UNIT: ppdt.UNIT, MREFLO0: ppdt.MREFLO0, MREFHI0: ppdt.MREFHI0, FREFLO0: ppdt.FREFLO0, FREFHI0: ppdt.FREFHI0, Decimalplace: ppdt.Decimalplace}).get(function (data) {
                            if (data == 'true') {
                                alert("保存成功");
                                $scope.getPpDeviceT();
                            }
                        })
                    }
//             $scope.updatePri=function(ppdt){
//                 base.post("pp/updatePpDeviceTest",{PK:ppdt.PK,DEVICEID:ppdt.DEVICEID,TESTID:ppdt.TESTID,DATA2:ppdt.DATA2}).get(function(data){
//                     if(data=='true'){
//                         alert("保存成功");
//                      $scope.getPpDeviceT();  
//                    }
//                 })
//             }
                    $scope.updatTestPK = function () {
                        base.post("pp/updateTestpk").get(function (data) {
                            if (data) {
                                alert("修改成功！");
                            }
                        })
                    }
                    $scope.getUnit = function () {//单位
                        base.post("lisTes/getUnit").get(function (data) {
                            if (data) {
                                $scope.units = data;
                            }
                        })
                    }
                    $scope.getUnit();
                })
    </script>
</html>
